package zj.it.bhne.image;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;

import me.pqpo.smartcropperlib.view.CropImageView;

public class ResultActivity extends AppCompatActivity implements View.OnClickListener {

    public static Bitmap resultBitmap;
    private CropImageView result;
    private Button btn_ocr;
    private Context context;
    private Button btn_o;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result);
        context = this;
        initView();
    }

    private void initView() {
        result = findViewById(R.id.result);

        result.setImageToCrop(MainActivity.bitmap);
        btn_ocr = findViewById(R.id.btn_ocr);
        btn_ocr.setOnClickListener(this);
        btn_o = findViewById(R.id.btn_o);
        btn_o.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_ocr:
                resultBitmap = result.crop();
                Intent intent = new Intent(context, MainActivity.class);
                startActivity(intent);

                break;
            case R.id.btn_o:
                Animation animation = AnimationUtils.loadAnimation(this, R.anim.anim);
                result.setAnimation(animation);
                result.setImageToCrop(result.crop());
                break;
        }
    }

}
